import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import persistedState from 'vuex-persistedstate'

export default new Vuex.Store({
  state: {
    list: [],//初始状态整体数据
    accomplish: [],//已完成数据
    cancel: [],//取消的数据
    info: "",//事件待定项内容
    nextId: 1,//下一个id
    done: false,//状态
    name: 1,
    show:false,//弹出框
  },
  mutations: {
    cose(state){
      state.show=!state.show
    },
    //input框内容提交到初始未完成中
    lyk_sub(state) {
      var obj = {
        title: state.info.trim(),
        id: state.nextId,
        done: state.done
      }
      if (state.info.trim().length <= 0) {
        return alert("待定项内容不能为空")
      } else {
        state.list.push(obj)
        state.info = ""
        state.nextId++
      }

    },
    // 给info重新赋值
    setChangeValue(state, val) {
      state.info = val
    },
    // 点击取消到取消列表项
    getCancel(state, id) {
      const x = state.list.findIndex(x => x.id === id)
      if (x != -1) {
        console.log(state.cancel)
        state.cancel.push(state.list[x])
        state.list.splice(x, 1)
      }
    },
    //点击input框是false状态发生改变并移入到accomplish中
    getChangeInput(state, parms) {
      var x = state.list.findIndex(x => x.id === parms.id)
      if (x != -1) {
        state.list[x].done = parms.status
        if (state.list[x].done === true) {
          console.log(state.list[x].done)
          state.accomplish.push(state.list[x])
          state.list.splice(x, 1)
        }
      }
    },
    //在已取消页面点击恢复，恢复到未完成
    getRecover(state, id) {
      const x = state.cancel.findIndex(x => x.id === id)
      if (x !== -1) {
        state.list.push(state.cancel[x])
        state.cancel.splice(x, 1)
      }
    }



  },
  actions: {

  },
  modules: {
  },
  plugins: [persistedState()]
})
